import axios from '@/api'
import { IGrain } from '@/common/services/famer'
import { IProject } from '@/common/services/user'
import { IBasic } from './common'

export interface ISubsidy extends IGrain, ISubsidyBase {
  is_used: string;
  member_id: string;
  member_nam: string;
  member_addr: string
}

export interface ISubsidyBase {
  s_a_id: string;
  s_a_nam: string;
}

export interface IStatistics extends ISubsidyBase {
  used: string;
  member_total: string;
}

export interface IGetSubsidyList {
  request: {
    s_a_id: string;
    pay_id?: string;
  },
  response: Array<ISubsidy | IStatistics>
}

export interface IGetSubsidyStandard {
  response: {
    task_id: string;
    task_nam: string;
    task_doc: string;
    s_a_nams: string;
    pay_info: ISubsidyStandard[];
  }
}
export interface ISubsidyStandard {
  s_a_id: string;
  s_a_nam: string;
  pay_unit: string;
  pay_price: string;
}

export interface IBankReceiptBasic {
  bk_give_id: string;
  pay_id: string;
  bk_id: string;
  bk_order_id: string;
  bk_pay_price: string;
  bk_pay_time: string;
  bk_usr: string;
  bk_code: string;
  bk_name: string;
  bk_time: string;
}
export interface IBankReceipt extends IBankReceiptBasic {
  bk_pay_id: string;
  s_a_id: string;
  op_info: string;
  bk_id_name: string;
}

export interface IPayee {
  bk_bid: string;
  bk_user: string;
  bk_nam: string;
  bk_num: string;
}

export interface IGetBankReceipts {
  request: IBasic & Api.PageOptions,
  response: IBankReceipt[]
}

class PayServices {
  constructor() { }

  /**
   * 获取当前行政地区下去补贴农户/大户信息
   *
   * @returns
   * @memberof SubsidyServices
   */
  async getList(data: IGetSubsidyList['request'] & Api.PageOptions) {
    return axios.post<unknown, Api.ResponseListOptions<IGetSubsidyList['response']>>('/btbusiness/pay/get-pay-list', data)
  }


  /**
   * 获取当前行政区下导出execl数据
   *
   * @param {IGetSubsidyList['request']} data
   * @returns
   * @memberof PayServices
   */
  async getExportList(data: IGetSubsidyList['request']) {
    return axios.post<unknown, Api.ResponseListOptions<IGetSubsidyList['response']>>('/btbusiness/pay/export-pay-list', data, { customHandler: true, responseType: 'blob' })
  }

  /**
   * 获取当前行政区下申请清单execl
   *
   * @param {IGetSubsidyList['request']} data
   * @returns
   * @memberof PayServices
   */
  async getExportApplyList(data: IGetSubsidyList['request']) {
    return axios.post<unknown, Api.ResponseListOptions<IGetSubsidyList['response']>>('/btbusiness/pay/export-aply-list', data, { customHandler: true, responseType: 'blob' })
  }

  /**
   * 获取当前行政地区下已公示的待确认用户列表
   *
   * @param {IGetSubsidyList['request']} data
   * @returns
   * @memberof PayServices
   */
  async getPublishPreview(data: IGetSubsidyList['request']) {
    return axios.post<unknown, Api.ResponseOptions<IGetSubsidyList['response']>>('/btbusiness/pay/get-publish-user-list', data)
  }

  /**
   * 获取当前获取当前行政地区下统计数据
   *
   * @param {IGetSubsidyList['request']} data
   * @returns
   * @memberof PayServices
   */
  async getCountList(data: IGetSubsidyList['request']) {
    return axios.post<unknown, Api.ResponseListOptions>('/btbusiness/pay/get-pay-count-list', data)
  }

  /**
   * 生成辖区批次号
   *
   * @param {IGetSubsidyList['request']} data
   * @returns
   * @memberof PayServices
   */
  async generateNo(data: IGetSubsidyList['request']) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/pay/set-pay-id', data)
  }

  /**
   * 获取当前行政区下按批次号分组统计数据
   *
   * @param {(IGetSubsidyList['request']} data
   * @returns
   * @memberof PayServices
   */
  async getCountListByPayId(data: IGetSubsidyList['request']) {
    return axios.post<unknown, Api.ResponseListOptions>('/btbusiness/pay/get-pay-count-list-by-payid', data)
  }

  /**
   * 获取银行回单列表
   *
   * @param {(IBasic & Api.PageOptions)} data
   * @returns
   * @memberof PayServices
   */
  getBankReceipts(data: IGetBankReceipts['request']) {
    return axios.post<unknown, Api.ResponseListOptions<IGetBankReceipts['response']>>('/btbusiness/pay/get-bank-pay-list', data)
  }

  /**
   * 上传银行回单数据
   *
   * @param {(IBasic & { data: IBankReceiptBasic[] })} data
   * @returns
   * @memberof PayServices
   */
  setBankReceipt(data: IBasic & { data: IBankReceiptBasic[], file_nam?: string }) {
    return axios.post<Api.ResponseOptions & { msg: string[] }>('/btbusiness/pay/set-bank-pay', data, { customHandler: true })
  }

  /**
   * 获取银行回单统计数据
   *
   * @param {IGetBankReceipts['request']} data
   * @returns
   * @memberof PayServices
   */
  getBankReceiptsCount(data: IGetBankReceipts['request']) {
    return axios.post<unknown, Api.ResponseListOptions>('/btbusiness/pay/get-bank-pay-count-list', data)
  }

  /**
   * 编辑银行回单数据
   *
   * @param {Partial<IBankReceiptBasic>} data
   * @returns
   * @memberof PayServices
   */
  editBankReceipt(data: Partial<IBankReceiptBasic>) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/pay/edit-bank-list', data)
  }

  /**
   * 编辑收款人信息
   *
   * @param {Partial<IPayee>} data
   * @returns
   * @memberof PayServices
   */
  updatePayee(data: Partial<IPayee>) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/pay/edit-pay-info', data)
  }

  /**
   * 删除银行回单数据
   *
   * @param {{ s_a_id: string, iid: string }} data
   * @returns
   * @memberof PayServices
   */
  delBank(data: { s_a_id: string, iid: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/pay/del-bank-list', data)
  }

  /**
   * 查询上传日志
   *
   * @param {Partial<Api.PageOptions>} data
   * @returns
   * @memberof PayServices
   */
  getUploadLog(data: Partial<Api.PageOptions>) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/pay/get-upload-log', data)
  }

  /**
   * 查询收款人修改记录
   *
   * @param {Pick<ISubsidy, 'member_id'>} data
   * @returns
   * @memberof PayServices
   */
   getPayeeUpdateLogs(data: Pick<ISubsidy, 'member_id'>) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/pay/get-pay-info-log', data)
  }

  /**
   * 获取发放批次信息
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof PayServices
   */
  getPayBatch(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>('/btbusiness/pay/get-pay-batch', data)
  }
}

export const payServices = new PayServices()

export default PayServices
